package com.hejjon;

import java.util.LinkedList;

/**
 * @author: Nil
 * @date: 2024/10/20 22:10
 * @since: 1.0
 */
public class EffectiveChar {

    public static void main(String[] args) {

        String str = "]";
        boolean judge = judge(str);

        System.out.println(judge);

    }


    public static boolean judge(String str) {

        LinkedList<Character> list = new LinkedList<>();
        for (int i = 0; i < str.length(); i++) {
            char c = str.charAt(i);
            if (c == '(') {
                list.push(')');
            } else if (c == '[') {
                list.push(']');
            } else if (c == '{') {
                list.push('}');
            } else {
                if (!list.isEmpty() && c == list.peek()) {
                    // 弹出栈头元素
                    list.pop();
                } else {
                    return false;
                }
            }
        }
        if (list.isEmpty()) {
            return true;
        }
        return false;


    }



}
